<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateOrderTaskUpstreamVersion extends AbstractMigration
{
    public function up()
    {
        $this->table('order_task_upstream_version', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '订单上游任务版本信息'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('from_tenant_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '甲方租户id'])
            ->addColumn('to_tenant_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '乙方租户id'])
            ->addColumn('task_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '任务id'])
            ->addColumn('version_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '任务id'])
            ->addColumn('is_download', 'enum', ['values' => 'yes,no', 'default' => 'no', 'comment' => '是否下载'])
            ->addColumn('is_unzip', 'enum', ['values' => 'yes,no', 'default' => 'no', 'comment' => '是否已解压'])
            ->addColumn('download_at', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '下载时间'])
            ->addColumn('created_by', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建人',])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建时间',])
            ->addColumn('updated', 'integer', ['null' => false, 'limit' => 11, 'default' => 0,])
            ->addIndex(['to_tenant_id', 'task_id', 'version_id'], ['name' => 'idx_to_tenant_task_version', 'type' => 'unique'])
            ->save();
    }

    public function down()
    {
        $this->table('order_task_upstream_version')->drop()->save();
    }
}
